using MicroMsg.Manager;
using MicroMsg.Plugin;
using MicroMsg.Resource.@string;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.Page
{
	public class PluginListPage : BasePage
	{
		private const string TAG = "PluginListPage";
		private bool initState;
		internal Grid LayoutRoot;
		internal StackPanel ContentPanel;
		internal StackPanel installedPluginsLayout;
		internal MMToggleSwitch toggleShowInContacts;
		internal StackPanel unInstalledLayout;
		internal StackPanel unInstalledPluginsLayout;
		private bool _contentLoaded;
		public PluginListPage()
		{
			this.InitializeComponent();
			base.add_Unloaded(new RoutedEventHandler(this.onUnloaded));
		}
		private void onUnloaded(object sender, RoutedEventArgs e)
		{
		}
		protected override void OnPageIn(object[] object_0)
		{
			this.refreshView();
			this.toggleShowInContacts.IsChecked = ConfigMgr.getBool("SHOW_IN_CONTACTS_KEY", true);
			this.initState = true;
			this.toggleShowInContacts.Text = strings.Set_Plugin_ShowInContactList;
			OnToggleStateChanged onToggleStateChanged = new OnToggleStateChanged(this.checkedStateChanged);
			this.toggleShowInContacts.onToggleStateChanged = onToggleStateChanged;
		}
		private void checkedStateChanged(object sender, bool isCheckOn)
		{
			if (this.initState && sender == this.toggleShowInContacts)
			{
				ConfigMgr.setBool("SHOW_IN_CONTACTS_KEY", this.toggleShowInContacts.IsChecked);
			}
		}
		protected override void OnPageBack()
		{
			this.refreshView();
		}
		private void refreshView()
		{
			this.installedPluginsLayout.get_Children().Clear();
			List<PluginBase> installedList = PluginManager.getInstalledList();
			if (installedList != null && installedList.get_Count() > 0)
			{
				using (List<PluginBase>.Enumerator enumerator = installedList.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						PluginBase current = enumerator.get_Current();
						PluginItemView pluginItemView = new PluginItemView();
						pluginItemView.InitData(current);
						this.installedPluginsLayout.get_Children().Add(pluginItemView);
					}
				}
			}
			this.unInstalledPluginsLayout.get_Children().Clear();
			List<PluginBase> uninstalledList = PluginManager.getUninstalledList();
			if (uninstalledList != null && uninstalledList.get_Count() > 0)
			{
				this.unInstalledLayout.set_Visibility(0);
				using (List<PluginBase>.Enumerator enumerator2 = uninstalledList.GetEnumerator())
				{
					while (enumerator2.MoveNext())
					{
						PluginBase current2 = enumerator2.get_Current();
						PluginItemView pluginItemView2 = new PluginItemView();
						pluginItemView2.InitData(current2);
						this.unInstalledPluginsLayout.get_Children().Add(pluginItemView2);
					}
					return;
				}
			}
			this.unInstalledLayout.set_Visibility(1);
		}
		private void removePluinItems(Panel layout)
		{
			if (layout != null && layout.get_Children().get_Count() > 0)
			{
				List<UIElement> list = new List<UIElement>();
				using (IEnumerator<UIElement> enumerator = layout.get_Children().GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						UIElement current = enumerator.get_Current();
						if (current.GetType() == typeof(PluginItemView))
						{
							list.Add(current);
						}
					}
				}
				using (List<UIElement>.Enumerator enumerator2 = list.GetEnumerator())
				{
					while (enumerator2.MoveNext())
					{
						UIElement current2 = enumerator2.get_Current();
						layout.get_Children().Remove(current2);
					}
				}
			}
		}
		protected override void OnPageOut()
		{
		}
		private string trimToEmpty(string string_0)
		{
			if (string_0 != null)
			{
				return string_0.Trim();
			}
			return "";
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Setting/PluginListPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.ContentPanel = (StackPanel)base.FindName("ContentPanel");
			this.installedPluginsLayout = (StackPanel)base.FindName("installedPluginsLayout");
			this.toggleShowInContacts = (MMToggleSwitch)base.FindName("toggleShowInContacts");
			this.unInstalledLayout = (StackPanel)base.FindName("unInstalledLayout");
			this.unInstalledPluginsLayout = (StackPanel)base.FindName("unInstalledPluginsLayout");
		}
	}
}
